package com.jack.userservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;
import java.util.List;

@SpringBootApplication
@EnableFeignClients
//@EnableJack
public class UserServiceApplication implements ApplicationRunner {

    public static void main(String[] args) {

        SpringApplication.run(UserServiceApplication.class, args);
    }
    
    // 向Spring IoC容器中注入RestTemplate
    @Bean
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    // 向Spring IoC容器中注入RestTemplate
    @Bean
    @LoadBalanced  // 让该RestTemplate具备Ribbon的能力
    public RestTemplate ribbonRestTemplate(){
        return new RestTemplate();
    }

    @Autowired  // 表示从Spring IoC容器中获取到Spring类型的Bean，并且存放到List集合中
    @LoadBalanced
    private List<String> list= Collections.emptyList();

    @Bean
    public String a(){
        return "a";
    }

    @Bean
    @LoadBalanced
    public String b(){
        return "b";
    }

    @Bean
    @LoadBalanced
    public String c(){
        return "c";
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println(list);
    }
}
























